package com.cloudschool.content.api;

import com.cloudschool.base.model.RestResponse;
import com.cloudschool.content.model.dto.BindTeachPlanMediaDto;
import com.cloudschool.content.model.dto.SaveTeachplanDto;
import com.cloudschool.content.model.dto.TeachplanDto;
import com.cloudschool.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author chenhong
 * @version 1.0
 * @description  课程计划编辑接口
 * @date 2023/3/9 15:24
 */
@Api(value = "课程计划编辑接口",tags = "课程计划编辑接口")
@RestController
public class TeachplanController {
    @Autowired
    TeachplanService teachplanService;

    @ApiOperation("查询课程计划树形结构")
    @ApiImplicitParam(value = "courseId",name = "课程Id",required = true,dataType = "Long",paramType = "path")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId){
        return teachplanService.findTeachplanTree(courseId);
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachPlan( @RequestBody SaveTeachplanDto teachplan){
        teachplanService.saveOrUpdateTeachPlan(teachplan);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachPlanMediaDto bindTeachplanMediaDto){
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }


    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public RestResponse associationMedia(@PathVariable Long  teachPlanId,@PathVariable String mediaId){
        return teachplanService.deleteAssociationMedia(teachPlanId,mediaId);
    }
}
